<?php

namespace backend\models;

use Yii;


/**
 * This is the model class for table "base_sys_fabric".
 *
 * @property integer $id
 * @property string $name
 * @property integer $img_small_id
 * @property integer $img_thumb_id
 * @property integer $img_url_id
 */
class Fabric extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'base_sys_fabric';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['img_small_id', 'img_thumb_id', 'img_url_id'], 'integer'],
            [['name'], 'string', 'max' => 32]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => Yii::t('app','Fabric Name'),
            'img_small_id' => 'Img Small ID',
            'img_thumb_id' => 'Img Thumb ID',
            'img_url_id' => 'Img Url ID',
        ];
    }
    
    public function getFabricUrlImage()
    {
    	return $this->hasOne(Image::className(),['id'=>'img_url_id'])->from(['fabricUrlImage'=>Image::tableName()]);
    }
    public function getFabricThumbImage()
    {
    	return $this->hasOne(Image::className(),['id'=>'img_thumb_id'])->from(['fabricThumbImage'=>Image::tableName()]);
    }
    public function getFabricSmallImage()
    {
    	return $this->hasOne(Image::className(),['id'=>'img_small_id'])->from(['fabricSmallImage'=>Image::tableName()]);
    }
    public function findNameById($id){
        $info = self::findOne($id);
        return $info ? $info->name : '';
    }
}
